package com.bdqn.springbootmybatisplus.controller;

import com.bdqn.springbootmybatisplus.pojo.SysUser;
import com.bdqn.springbootmybatisplus.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Calendar;
import java.util.List;

/**
 * 演示Demo
 *
 * @author
 * @since
 */
@Controller
@RequestMapping("/user")
public class DemoController {

    @Resource
    private SysUserService userService;

    @GetMapping("/test")
    public Object hello(Model model) {
        return "demo/test";
    }

    @GetMapping("/hello/{id}")
    public Object hello(Model model, HttpServletRequest request, HttpSession session, @PathVariable("id") Long id) {
        System.out.println("---------------------- /user/test ----------------------");
        SysUser user = userService.getById(id);

        List<SysUser> list = userService.list(null);

        Calendar c = Calendar.getInstance();
        model.addAttribute("sss", c.getTime());

        model.addAttribute("user", user);

        model.addAttribute("users", list);

        session.setAttribute("s_user", user);
        return "demo/hello";
    }

}
